<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


<!-- remove old header -->


<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>cogen API Reference Documentation
        - Class: Socket</title><meta name="MSSmartTagsPreventParsing" content="true" /><meta http-equiv="imagetoolbar" content="no" /><link href="css/default.css" rel="stylesheet" type="text/css" /><link href="css/pygments.css" rel="stylesheet" type="text/css" />
    <!-- <link rel="shortcut icon" href="/images/favicon.ico" type="image/vnd.microsoft.icon"/> -->
    <link rel="stylesheet" href="css/apydia.css" type="text/css" />
    <script src="js/jquery-1.2.1.pack.js" type="text/javascript"></script>
    <script src="js/apydia.js" type="text/javascript"></script>
	<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
    <div id="page">
        <div id="browser">
            <div class="browser-section">
                <h2>Module Index</h2>
                <ul>
                    <li>
                        <a href="cogen.html">cogen</a>
                    </li><li>
                        <a href="cogen.common.html">cogen.common</a>
                    </li><li>
                        <a href="cogen.core.html">cogen.core</a>
                    </li><li>
                        <a href="cogen.core.coroutines.html">cogen.core.coroutines</a>
                    </li><li>
                        <a href="cogen.core.events.html">cogen.core.events</a>
                    </li><li>
                        <a href="cogen.core.pubsub.html">cogen.core.pubsub</a>
                    </li><li>
                        <a href="cogen.core.queue.html">cogen.core.queue</a>
                    </li><li>
                        <a href="cogen.core.reactors.html">cogen.core.reactors</a>
                    </li><li>
                        <a href="cogen.core.reactors.base.html">cogen.core.reactors.base</a>
                    </li><li>
                        <a href="cogen.core.reactors.iocp_proactor.html">cogen.core.reactors.iocp_proactor</a>
                    </li><li>
                        <a href="cogen.core.reactors.poll_reactor.html">cogen.core.reactors.poll_reactor</a>
                    </li><li>
                        <a href="cogen.core.reactors.qt_reactor.html">cogen.core.reactors.qt_reactor</a>
                    </li><li>
                        <a href="cogen.core.reactors.select_reactor.html">cogen.core.reactors.select_reactor</a>
                    </li><li>
                        <a href="cogen.core.schedulers.html">cogen.core.schedulers</a>
                    </li><li class="active">
                        <a href="cogen.core.sockets.html">cogen.core.sockets</a>
                    </li><li>
                        <a href="cogen.core.util.html">cogen.core.util</a>
                    </li><li>
                        <a href="cogen.web.html">cogen.web</a>
                    </li><li>
                        <a href="cogen.web.async.html">cogen.web.async</a>
                    </li><li>
                        <a href="cogen.web.wsgi.html">cogen.web.wsgi</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>cogen.core.sockets</h2>
                <ul>
                    <li>
                        <a href="cogen.core.sockets.Accept.html">Accept</a>
                    </li><li>
                        <a href="cogen.core.sockets.Connect.html">Connect</a>
                    </li><li>
                        <a href="cogen.core.sockets.Read.html">Read</a>
                    </li><li>
                        <a href="cogen.core.sockets.ReadAll.html">ReadAll</a>
                    </li><li>
                        <a href="cogen.core.sockets.ReadLine.html">ReadLine</a>
                    </li><li>
                        <a href="cogen.core.sockets.SendFile.html">SendFile</a>
                    </li><li class="active">
                        <a href="cogen.core.sockets.Socket.html">Socket</a>
                    </li><li>
                        <a href="cogen.core.sockets.SocketOperation.html">SocketOperation</a>
                    </li><li>
                        <a href="cogen.core.sockets.Write.html">Write</a>
                    </li><li>
                        <a href="cogen.core.sockets.WriteAll.html">WriteAll</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Constructor</h2>
                <ul>
                    <li>
                        <a href="cogen.core.sockets.Socket.html#constructor">__init__</a>
                    </li>
                </ul>
            </div>
            <div class="browser-section">
                <h2>Methods</h2>
                <ul>
                    <li>
                        <a href="cogen.core.sockets.Socket.html#method-accept">accept</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-bind">bind</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-close">close</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-connect">connect</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-fileno">fileno</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-getpeername">getpeername</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-getsockname">getsockname</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-gettimeout">gettimeout</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-listen">listen</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-read">read</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-readall">readall</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-readline">readline</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-setblocking">setblocking</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-setsockopt">setsockopt</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-settimeout">settimeout</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-shutdown">shutdown</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-write">write</a>
                    </li><li>
                        <a href="cogen.core.sockets.Socket.html#method-writeall">writeall</a>
                    </li>
                </ul>
            </div>
        </div>
        <div id="content">
    <h1>Class: cogen.core.sockets.Socket</h1>
    <div class="docstring rst"><p>A wrapper for socket objects, sets nonblocking mode and
adds some internal bufers and wrappers. Regular calls to the usual
socket methods return operations for use in a coroutine.</p>
<p>So you use this in a coroutine like:</p>
<div class="source"><pre><span class="n">sock</span> <span class="o">=</span> <span class="n">Socket</span><span class="p">(</span><span class="n">family</span><span class="p">,</span> <span class="nb">type</span><span class="p">,</span> <span class="n">proto</span><span class="p">)</span> <span class="c"># just like the builtin socket module</span>
<span class="k">yield</span> <span class="n">sock</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mf">1024</span><span class="p">)</span>
</pre></div>
<p>Constructor details:</p>
<div class="source"><pre><span class="n">Socket</span><span class="p">([</span><span class="n">family</span><span class="p">[,</span> <span class="nb">type</span><span class="p">[,</span> <span class="n">proto</span><span class="p">]]])</span> <span class="o">-&gt;</span> <span class="n">socket</span> <span class="nb">object</span>
</pre></div>
<p>Open a socket of the given type.  The family argument specifies the
address family; it defaults to AF_INET.  The type argument specifies
whether this is a stream (SOCK_STREAM, this is the default)
or datagram (SOCK_DGRAM) socket.  The protocol argument defaults to 0,
specifying the default protocol.  Keyword arguments are accepted.</p>
<p>A socket object represents one endpoint of a network connection.</p>
</div>
    <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#47">View source</a>
    </li>
</ul>
    <div>
        <h2>Constructor</h2>
        <h3 id="constructor">
            __init__
            <span class="args">(self, *a, **k)</span>
        </h3>
        <div class="docstring rst"></div>
        <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#76">View source</a>
    </li>
</ul>
    </div>
    <div>
        <h2>Methods</h2>
            <h3 id="method-accept">
                accept
                <span class="args">(self, **kws)</span>
            </h3>
            <div class="docstring rst"><p>Accept a connection. The socket must be bound to an address and
listening for connections. The return value is a pair (conn, address)
where conn is a new socket object usable to send and receive data on the
connection, and address is the address bound to the socket on the other
end of the connection.</p>
<p>Example:
{{{
conn, address = yield mysock.accept()
}}}</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#115">View source</a>
    </li>
</ul>
            <h3 id="method-bind">
                bind
                <span class="args">(self, *args)</span>
            </h3>
            <div class="docstring rst"><p>Bind the socket to _address_. The socket must not already be bound.
(The format of _address_ depends on the address family)</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#136">View source</a>
    </li>
</ul>
            <h3 id="method-close">
                close
                <span class="args">(self, *args)</span>
            </h3>
            <div class="docstring rst"><p>Close the socket. All future operations on the socket object will
fail. The remote end will receive no more data (after queued data is
flushed). Sockets are automatically closed when they are garbage-collected.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#129">View source</a>
    </li>
</ul>
            <h3 id="method-connect">
                connect
                <span class="args">(self, address, **kws)</span>
            </h3>
            <div class="docstring rst"><p>Connect to a remote socket at _address_.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#142">View source</a>
    </li>
</ul>
            <h3 id="method-fileno">
                fileno
                <span class="args">(self)</span>
            </h3>
            <div class="docstring rst"><p>Return the socket's file descriptor</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#146">View source</a>
    </li>
</ul>
            <h3 id="method-getpeername">
                getpeername
                <span class="args">(self)</span>
            </h3>
            <div class="docstring rst"><p>Return the remote address to which the socket is connected.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#157">View source</a>
    </li>
</ul>
            <h3 id="method-getsockname">
                getsockname
                <span class="args">(self, *args)</span>
            </h3>
            <div class="docstring rst"><p>Return the socket's own address.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#161">View source</a>
    </li>
</ul>
            <h3 id="method-gettimeout">
                gettimeout
                <span class="args">(self, *args)</span>
            </h3>
            <div class="docstring rst"><p>Return the associated timeout value.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#171">View source</a>
    </li>
</ul>
            <h3 id="method-listen">
                listen
                <span class="args">(self, backlog)</span>
            </h3>
            <div class="docstring rst"><p>Listen for connections made to the socket. The _backlog_ argument
specifies the maximum number of queued connections and should be at
least 1; the maximum value is system-dependent (usually 5).</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#150">View source</a>
    </li>
</ul>
            <h3 id="method-read">
                read
                <span class="args">(self, bufsize, **kws)</span>
            </h3>
            <div class="docstring rst"><p>Receive data from the socket. The return value is a string
representing the data received. The amount of data may be less than the
ammount specified by _bufsize_.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#85">View source</a>
    </li>
</ul>
            <h3 id="method-readall">
                readall
                <span class="args">(self, bufsize, **kws)</span>
            </h3>
            <div class="docstring rst"><p>Receive data from the socket. The return value is a string
representing the data received. The amount of data will be the exact
ammount specified by _bufsize_.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#91">View source</a>
    </li>
</ul>
            <h3 id="method-readline">
                readline
                <span class="args">(self, size, **kws)</span>
            </h3>
            <div class="docstring rst"><p>Receive one line of data from the socket. The return value is a string
representing the data received. The amount of data will at most
ammount specified by _size_. If no line separator has been found and the
ammount received has reached _size_ an OverflowException will be raised.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#97">View source</a>
    </li>
</ul>
            <h3 id="method-setblocking">
                setblocking
                <span class="args">(self, val)</span>
            </h3>
            <div class="docstring rst"></div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#180">View source</a>
    </li>
</ul>
            <h3 id="method-setsockopt">
                setsockopt
                <span class="args">(self, *args)</span>
            </h3>
            <div class="docstring rst"><p>Set the value of the given socket option. Same as the usual socket
method.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#183">View source</a>
    </li>
</ul>
            <h3 id="method-settimeout">
                settimeout
                <span class="args">(self, to)</span>
            </h3>
            <div class="docstring rst"><p>Set a timeout on blocking socket operations. The value argument can
be a nonnegative float expressing seconds, timedelta or None.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#165">View source</a>
    </li>
</ul>
            <h3 id="method-shutdown">
                shutdown
                <span class="args">(self, *args)</span>
            </h3>
            <div class="docstring rst"><p>Shut down one or both halves of the connection. Same as the usual
socket method.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#175">View source</a>
    </li>
</ul>
            <h3 id="method-write">
                write
                <span class="args">(self, data, **kws)</span>
            </h3>
            <div class="docstring rst"><p>Send data to the socket. The socket must be connected to a remote
socket. Ammount sent may be less than the data provided.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#105">View source</a>
    </li>
</ul>
            <h3 id="method-writeall">
                writeall
                <span class="args">(self, data, **kws)</span>
            </h3>
            <div class="docstring rst"><p>Send data to the socket. The socket must be connected to a remote
socket. All the data is guaranteed to be sent.</p>
</div>
            <ul class="link-bar">
    <li class="link-to-sourcecode">
        <a href="http://code.google.com/p/cogen/source/browse/trunk/cogen/core/sockets.py#110">View source</a>
    </li>
</ul>
    </div>
        </div>
        <div id="footer">
            Generated with <a href="http://apydia.ematia.de/" class="extern">
            Apydia 0.0.3</a>
        </div>
    </div>
</body>
</html>